package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasFacilitiesTypeSpec;
import com.fas.system.service.IFasFacilitiesTypeSpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *  设施类型--规格 Controller
 *
 * @date 2022-07-01
 */
@Api(tags = "设施类型--规格")
@RestController
@RequestMapping("/system/facilities/type/spec")
public class FasFacilitiesTypeSpecController extends BaseController {
    
    @Resource
    private IFasFacilitiesTypeSpecService fasFacilitiesTypeSpecService;

    @ApiOperation(value = "通过设施类型查询设施规格列表")
    @GetMapping("/findListById")
    public TableDataInfo findListById(FasFacilitiesTypeSpec fasFacilitiesTypeSpec,Integer pageNum,Integer pageSize){
        startPage();
        return getDataTable(fasFacilitiesTypeSpecService.findByFacilityId(fasFacilitiesTypeSpec));
    }

    @ApiOperation(value = "新增设施类型-设施规格")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasFacilitiesTypeSpec fasFacilitiesTypeSpec){
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        int addMethod = deptId == 100 ? 1 : 2;
        fasFacilitiesTypeSpec.setAddMethod(addMethod);
        return fasFacilitiesTypeSpecService.addFasFacilitiesTypeSpec(fasFacilitiesTypeSpec);
    }

    @ApiOperation(value = "修改设施类型-设施规格")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasFacilitiesTypeSpec fasFacilitiesTypeSpec){
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        int addMethod = deptId == 100 ? 1 : 2;
        fasFacilitiesTypeSpec.setAddMethod(addMethod);
        return toAjax(fasFacilitiesTypeSpecService.editFasFacilitiesTypeSpec(fasFacilitiesTypeSpec));
    }

    @ApiOperation(value = "删除设施类型-设施规格")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") String id){
        return toAjax(fasFacilitiesTypeSpecService.deleteFasFacilitiesTypeSpec(id));
    }

    @ApiOperation(value = "设施类型-设施规格-是否启用")
    @PostMapping("/enable")
    public AjaxResult enableDataItem(@RequestBody FasFacilitiesTypeSpec fasFacilitiesTypeSpec){
        return toAjax(fasFacilitiesTypeSpecService.enableSpec(fasFacilitiesTypeSpec));
    }
}
